package com.usian.entity;

import com.usian.entity.ResultCodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;



/**
 * @Author:张永杰
 * @ClassName: Result
 * @Date: 2024/11/25
 * @Description:
 */
@Data
@Schema(description = "通用返回结果")
public class Result<T> {
    @Schema(description = "业务状态码")
    private Integer code;
    @Schema(description = "响应信息")
    private String message;
    @Schema(description = "响应数据")
    private T data;

    // 返回数据
    public static <T> Result<T> build(T body, Integer code, String message) {
        Result<T> result = new Result<>();
        result.setData(body);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    // 通过枚举构造Result对象   魔法值
    public static <T> Result build(T body , ResultCodeEnum resultCodeEnum) {
        return build(body , resultCodeEnum.getCode() , resultCodeEnum.getMessage()) ;
    }


}
